#pragma once

#ifndef _CTREASUREPOOL_H_
#define _CTREASUREPOOL_H_

#include "CChar.h"

class CTreasurePool {

private:

	struct lotInfo {
		CChar* member;
		unsigned short lot;
	};

	struct treasurePoolItem {
		unsigned short itemID;
		unsigned long itemQuantity;
		unsigned long timestamp;
		std::vector<struct lotInfo> itemLotters;
	};

	//Returns the winner and the winning lot number for a slot ID
	//	In the event of a tie it will randomly generate a winner
	struct lotInfo getWinner(unsigned char slotID);

	//Returns 1 if the item can be won (timeout or all lotted) or 0 if its not ready to be won
	int checkItem(unsigned char slotID);

	//Sends a packet to all members in the treasure pool
	int sendToMembers(CBasicPacket pack);

	unsigned short m_poolType;

	//the last time the server checked this pool for updates
	unsigned int m_lastCheckTime;

	struct treasurePoolItem m_poolItems[10];
	
	//Treasure Pool Members
	std::vector<CChar*> m_members;
	
	CSemaphore* m_pTreasurePoolSemaphore; //Locks and unlocks the treasurepool

public:
	CTreasurePool();
	~CTreasurePool();

	//Adds an item to the treasure pool, will remove the oldest item if nessessary
	//	BaseEntity is the thing that dropped the item
	void addItem(unsigned short itemID, unsigned int quantity, CBaseEntity * pEntity);

	//Returns true if the treasure pool has at least 1 item in it
	bool hasTreasure(void);

	//Lot item lots on an active item in the treasure pool
	void lotItem(CChar * lotter, unsigned char slotID, unsigned short lot);

	//Add member adds a new player to the treasure pool
	void addMember(CChar * member);
	
	//Remove member removes an exisiting member from the treasure pool
	void removeMember(CChar * member);

	//Checks the treasure pool for any items that will timeout and default to a player
	//	Also checks after a lot has been cast to see if everyone has voted
	void checkItems();
		
	//Returns what type of treasure pool (Solo/Party or zone-wide)
	unsigned short getPoolType();
	
	//Sets the treasure pool type
	void setPoolType(unsigned short poolType);

	//Gets the last time the treasure pool was checked for an update
	unsigned int CTreasurePool::getLastCheckTime();

	//Sets the last time the treasure pool was checked
	void CTreasurePool::setLastCheckTime(unsigned int lastCheckTime);

	//Locks the semaphore for the treasure pool
	bool lockTreasurePool();
	
	//Unlocks the treasure pool semaphore
	bool unlockTreasurePool();
	
};

/*  ADDITONS TO STRUCTS.H

struct treasurePoolItem {
	unsigned short itemID;
	unsigned int itemQuantity;
	unsigned int timestamp;
	std::vector<struct lotInfo> itemLotters;
};

struct lotInfo {
	CChar* member;
	unsigned short lot;
};


*/


#endif